package com.i.template.service.impl;

import cn.hutool.system.JvmInfo;
import cn.hutool.system.RuntimeInfo;
import cn.hutool.system.SystemUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import com.i.template.domain.vo.CpuVO;
import com.i.template.domain.vo.JvmVO;
import com.i.template.domain.vo.MemoryVO;
import com.i.template.domain.vo.SysVO;
import com.i.template.service.ISystemService;
import org.springframework.stereotype.Service;
import oshi.software.os.OperatingSystem;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/8/9
 */
@Service
public class SystemServiceImpl implements ISystemService {
    @Override
    public SysVO getSysInfo() {
        return SysVO.builder()
                .osName(OshiUtil.getOs().getVersionInfo().getVersion())
                .osArch(OshiUtil.getHardware().getComputerSystem().getFirmware().getVersion())
                .computerIp(SystemUtil.getHostInfo().getAddress())
                .build();
    }

    @Override
    public CpuVO getCpuInfo() {
        CpuInfo cpuInfo = OshiUtil.getCpuInfo();
        return CpuVO.builder().cpuNum(cpuInfo.getCpuNum())
                .total(cpuInfo.getToTal())
                .sys(cpuInfo.getSys())
                .used(cpuInfo.getUsed())
                .wait(cpuInfo.getWait())
                .free(cpuInfo.getFree())
                .build();
    }

    @Override
    public JvmVO getJVMInfo() {
        RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo();
        return JvmVO.builder()
                .total(runtimeInfo.getTotalMemory())
                .max(runtimeInfo.getMaxMemory())
                .free(runtimeInfo.getFreeMemory())
                .version(System.getProperty("java.version"))
                .home("java.home")
                .build();
    }

    @Override
    public MemoryVO getMemoryInfo() {
        return null;
    }
}
